package com.ilearn.autocomplie.config;

import com.ilearn.autocomplie.code.AutoCompileLoader;
import com.ilearn.autocomplie.code.CustomFactoryBean;
import com.ilearn.autocomplie.entities.EdmProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author: lyndon
 * @version: 1.0
 * @date: 2019/1/28
 */

@Configuration
public class CustomBeanConfig {


    private CustomFactoryBean customFactoryBean;

    @Autowired
    public CustomBeanConfig(CustomFactoryBean customFactoryBean) {
        this.customFactoryBean = customFactoryBean;
        customGenerateBean();
    }


    public void customGenerateBean() {
        List<EdmProperty> edmPropertyList = new ArrayList<EdmProperty>();
        edmPropertyList.add(EdmProperty.builder().tableName("members").columnNames(Arrays.asList("id", "name", "age")).columnTypes(Arrays.asList("String", "String", "Integer")).build());
        edmPropertyList.add(EdmProperty.builder().tableName("rights").columnNames(Arrays.asList("id", "role", "resource")).columnTypes(Arrays.asList("Integer", "String", "String")).build());

        for (EdmProperty edmProperty : edmPropertyList) {
            AutoCompileLoader autoCompileLoader = new AutoCompileLoader(edmProperty.getTableName(), edmProperty.getColumnNames(), edmProperty.getColumnTypes());
            customFactoryBean.setAutoCompileLoader(autoCompileLoader);

        }

    }

}


